import request from '@/utils/request';
import { IExecutesqlParams, url } from '@/api/url';
import { IDistinctvaluePararm } from '@/pages/Analysis/type';

// 存储看板创建分组
export async function saveCreateGroup(params: any) {
  return request(url.createGroup, {
    method: 'POST',
    data: params,
  });
}

// 重命名分组
export async function saveRenameGroup(params: any) {
  return request(url.renameGroup(params), {
    method: 'POST',
  });
}

// 删除分组
export async function removeGroup(params: any) {
  return request(url.removeGroup(params), {
    method: 'DELETE',
  });
}
export async function renameDashboard(params: any) {
  return request(url.renameDashboardUrl(params), {
    method: 'POST',
  });
}

// 添加指标
export async function addWidgets(params: any) {
  return request(url.addWidgetsUrl(params), {
    method: 'POST',
    data: params.widgets,
  });
}

// 看板删除指标
export async function deleteWidgets(params: any) {
  return request(url.deleteWidgets(params), {
    method: 'DELETE',
  });
}

// 更新分组指标
export async function updateGroup(params: any) {
  return request(url.updateGroup(params), {
    method: 'POST',
    data: params.widgets,
  });
}

// 数据表-获取权限范围内的所有视图
export async function getSheetList(): Promise<any> {
  return request(url.querySheetList);
}

// 单个项目数据表-获取权限范围内的所有视图
export async function getSheetListByProjrctId(projectId:number): Promise<any> {
  return request(url.querySheetListByProjectIdUrl(projectId));
}

export async function getWidgetByProjectId(params: any): Promise<any> {
  return request(url.queryWidgetByProjectIdUrl(params));
}

// 数据表-更新视图model
export async function saveEditModel(params: any) {
  return request(url.saveModel, {
    method: 'POST',
    data: params,
  });
}

// 设置全局过滤器
export async function setGrobalFilter(params: any) {
  return request(url.setGrobalFilterUrl, {
    method: 'POST',
    data: params,
  });
}

export async function queryGrobalFilterByUrl(params: any): Promise<any> {
  return request(url.queryGrobalFilterByUrl(params));
}

/**
 * 获取看板数据及操作行为日志
 * @param params
 */
export async function queryDashboardOperation(params: any): Promise<any> {
  return request(url.queryDashboardOperation(params));
}

// 新增文件夹
export async function addFolder(params: any) {
  return request(url.addFolderUrl(params), {
    method: 'POST',
    data: params.body,
  });
}

export async function getdistinctvalue(viewId: number, params: IDistinctvaluePararm) {
  return request(url.getDistinctValueUrl(viewId), {
    method: 'POST',
    body: JSON.stringify(params)
  });
}
export async function updateFilterConfig(params: {id:number,config:string}) {
  return request(url.updateFilterConfigUrl(), {
    method: 'PUT',
    body: JSON.stringify(params)
  });
}
export async function executesql(params:IExecutesqlParams) {
  return request(url.executesqlUrl, {
    method: 'POST',
    body: JSON.stringify(params)
  });
}
